within ThreeD_MBS_Dynamics.Examples.OmniVehicle.PatchContact;

model RollerContactForces
  extends RollerContactVelocities;
  parameter Real delta = 10^(-6);
  parameter Real fric = 0.1;
  parameter Real stiff = 1000;
  parameter Real damp = 100;
//  Real mu;
  Real[3] Forcet;
  Real Forcen;
  Real Forcev;
  Real w;
equation
  w = abs((InPortB.T*i)*nA) - cos_of_max;
  if noEvent(w < 0 and kappa < 0) then
    Forcen = -stiff*kappa*sqrt(abs(kappa));
  else
    Forcen = 0;
  end if;
  Forcet = -fric*relvt*(if relvtsqrt <= delta then 1/delta else 1/relvtsqrt)*Forcen;
//  Forcet = -fric*relvt*(if relvtsqrt <= delta then 1/delta else 1/relvtsqrt)*Forcen + mu*nA;
  if noEvent(w < 0 and kappa < 0) then
//    Forcev =  - (if noEvent(relvn > 0) then d*(-kappa)*sqrt(relvn)*sqrt(sqrt(relvn)) else 0);
//    Forcev =  -d*(if noEvent(relvn > 0) then (-kappa)*exp(0.75*log(relvn)) else -(-kappa)*exp(0.75*log(-relvn)));
//    Forcev =  - (if noEvent(relvn > 0) then d*(-kappa)*sqrt(relvn) else 0);
    Forcev =  if noEvent(relvn < 0) then damp*kappa*relvn else 0;
//    Forcev =  - (if noEvent(relvn > 0) then d*(-kappa)^2*sqrt(relvn)*sqrt(sqrt(relvn)) else 0);
  else
    Forcev = 0;
  end if;

  OutPortB.F = Forcet + Forcen*nA + Forcev*nA;
  OutPortB.M = zeros(3);
end RollerContactForces;
